package com.zian.controller.admin;


import com.zian.annotation.OperLog;
import com.zian.common.R;
import com.zian.domain.dto.GoodsInfoDTO;
import com.zian.domain.dto.PageDTO;
import com.zian.domain.po.SysGoodsInfo;
import com.zian.domain.query.GoodsQuery;
import com.zian.domain.vo.GoodsInfoVO;
import com.zian.domain.vo.GoodsQueryVO;
import com.zian.enums.BusinessType;
import com.zian.service.ISysGoodsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2024-09-08
 */
@Slf4j
@Api("商品信息接口")
@RestController("SysGoodsInfoControllerAdmin")
@RequestMapping("/admin/goods-infos")
@RequiredArgsConstructor
public class SysGoodsInfoController {

    private final ISysGoodsInfoService goodsInfoService;

    @GetMapping("/page")
    @ApiOperation("分页查询商品信息")
    public R<PageDTO<GoodsQueryVO>> queryGoodsInfoPage(GoodsQuery query) {
        log.info("分页查询商品信息参数：query：{}", query);
        PageDTO<GoodsQueryVO> vo = goodsInfoService.queryGoodsInfoPage(query);
        return R.ok(vo);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询商品详情")
    public R<GoodsInfoVO> queryGoodsInfoDetail(@PathVariable Long id) {
        log.info("查询商品详情参数：id：{}", id);
        GoodsInfoVO vo = goodsInfoService.queryGoodsInfoDetail(id);
        return R.ok(vo);
    }


    @DeleteMapping
    @ApiOperation("删除商品信息 - 批量删除")
    @OperLog(title = "商品模块", businessType = BusinessType.DELETE)
    public R deleteGoodsInfoByIds(@RequestParam("ids") List<Long> ids) {
        log.info("删除商品信息参数：id：{}", ids);
        goodsInfoService.deleteGoodsInfoByIds(ids);
        return R.ok();
    }

    @PutMapping
    @ApiOperation("修改商品信息")
    @OperLog(title = "商品模块", businessType = BusinessType.UPDATE)
    public R updateGoodsInfo(@RequestBody GoodsInfoDTO dto) {
        log.info("修改商品信息参数：dto：{}", dto);
        goodsInfoService.updateGoodsInfo(dto);
        return R.ok();
    }

    @PostMapping
    @ApiOperation("新增商品信息")
    @OperLog(title = "商品模块", businessType = BusinessType.INSERT)
    public R addGoodsInfo(@RequestBody GoodsInfoDTO dto) {
        log.info("新增商品信息参数：dto：{}", dto);
        goodsInfoService.addGoodsInfo(dto);
        return R.ok();
    }

    @PutMapping("/{id}")
    @ApiOperation("修改商品上架状态")
    public R updateGoodsSellStatus(@PathVariable Long id) {
        log.info("修改商品上架状态参数：id：{}", id);
        goodsInfoService.updateGoodsSellStatus(id);
        return R.ok();
    }


}
